
import { toast, cardCache} from 'nc-lightapp-front';
import { AREA  } from '../../constance';
import { DOCLIST, STATUS } from "../../../../common/constant";
import { fiterDefdoc, fiterFrkm } from '../../../../common/util/fiterUtils';
let { getDefData } = cardCache;

/*
 * @Author: nccloud
 * @PageInfo: 表体编辑前事件
 */
export default async function(props, moduleId, key, value, index, oldvalue, refinfo) {
     
        if(key == 'vbdef6' ){ //利润中心部门
                let vdef5 = props.form.getFormItemsValue(AREA.cardHead, 'vdef5').value;
             
                if(vdef5 == ''){
                        toast({ color: STATUS.warning, content: '请先维护表头录单利润中心！' });
                        return false;
                }

                let where = "def1 in (select pk_org from org_orgs where dr=0 and name in (select name from org_orgs where pk_org='"+vdef5+"')) and def7 = 'Y'";
                fiterDefdoc(props, moduleId, key, where);

        }else if(key == 'acc'){
                let pk_org = props.form.getFormItemsValue('card_head', 'pk_org').value;
                let pk_accountingbook = getDefData("txaccbook","txaccbook");
                let fiterType = DOCLIST.txdjjf;
                fiterFrkm(props, moduleId, key, pk_org, pk_accountingbook, fiterType);
        }else if(key == 'vbdef2'){//费用明细
                let def1 = props.cardTable.getValByKeyAndIndex(AREA.cardBody_1, index, 'vbdef1').value;
                if(def1 == ''){
                        toast({ color: STATUS.warning, content: '请先维护费报销类型！' });
                        return false;
                }
                let where = "def11 = '"+def1+"'";

                fiterDefdoc(props, moduleId, key, where);

        }else if(key == 'vbdef7'){//管理会计科目
                let def1 = props.cardTable.getValByKeyAndIndex(AREA.cardBody_1, index, 'vbdef1').value;
                let where = "def11 = '"+def1+"'";
                if(def1 == ''){
                        toast({ color: STATUS.warning, content: '请先维护报销类型！' });
                        return false;
                }
                
                fiterDefdoc(props, moduleId, key, where);
        }
        
        return true;
}
